/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DialogCadFornecedor.java
 *
 * Created on 04/07/2011, 14:04:32
 */
package camada.apresentacao.dialog.fornecedor;

import camada.bancodedados.daoimplemente.fornecedor.FornecedorDAOImpl;
import eloma.classe.Fornecedor;
import javax.swing.JOptionPane;
import utilitarios.Exceptions;
import utilitarios.LimitarTamanhoTextField;

/**
 *
 * @author prado
 */
public class DialogCadFornecedor extends javax.swing.JDialog {

    boolean edicao = false;
    FornecedorDAOImpl daoFornecedor = new FornecedorDAOImpl();
    Fornecedor fornecedor = new Fornecedor();
    Exceptions exceptions = new Exceptions();
    int idFornecedor = 0;
    
    /** Creates new form DialogCadFornecedor */
    public DialogCadFornecedor(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        this.setTitle("Cadastro Fornecedores");
        this.setLocationRelativeTo(null);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txNome = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        txEndereco = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        txCidade = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        txCep = new javax.swing.JFormattedTextField();
        jLabel7 = new javax.swing.JLabel();
        txBairro = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        cmEstado = new javax.swing.JComboBox();
        jLabel8 = new javax.swing.JLabel();
        txTelefone = new javax.swing.JFormattedTextField();
        txEmail = new javax.swing.JTextField();
        txCelular = new javax.swing.JFormattedTextField();
        jLabel10 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        txCPNJ = new javax.swing.JFormattedTextField();
        jLabel12 = new javax.swing.JLabel();
        txContato = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        txtEE = new javax.swing.JFormattedTextField();
        btCancelar = new javax.swing.JButton();
        btSalvar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        jLabel1.setText("Nome/Razão Social:");

        txNome.setDocument(new LimitarTamanhoTextField(65));

        jLabel3.setText("Contato:");

        jLabel4.setText("Endereço:");

        txEndereco.setDocument(new LimitarTamanhoTextField(65));
        txEndereco.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txEnderecoActionPerformed(evt);
            }
        });

        jLabel5.setText("Cidade:");

        txCidade.setDocument(new LimitarTamanhoTextField(47));

        jLabel6.setText("CEP:");

        txCep.setBackground(new java.awt.Color(0, 255, 255));
        try {
            txCep.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##.###-###")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        jLabel7.setText("Bairro:");

        txBairro.setDocument(new LimitarTamanhoTextField(37));

        jLabel11.setText("UF:");

        cmEstado.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "AC", "AL", "AP", "AM", "BA", "CE", "DF", "ES", "GO", "MA", "MT", "MS", "MG", "PA", "PB", "PR", "PE", "PI", "RJ", "RN", "RS", "RO", "RR", "SC", "SP", "SE", "TO" }));

        jLabel8.setText("Telefone:");

        try {
            txTelefone.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##)####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        txEmail.setDocument(new LimitarTamanhoTextField(47));
        txEmail.setBackground(new java.awt.Color(0, 255, 255));

        txCelular.setBackground(new java.awt.Color(0, 255, 255));
        try {
            txCelular.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("(##)####-####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        jLabel10.setText("Celular:");

        jLabel9.setText("E-mail:");

        txCPNJ.setBackground(new java.awt.Color(0, 255, 255));
        try {
            txCPNJ.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##.###.###/####-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        jLabel12.setText("CNPJ:");

        txContato.setDocument(new LimitarTamanhoTextField(65));

        jLabel2.setText("Escrição Estadual:");

        txtEE.setBackground(new java.awt.Color(0, 255, 255));
        try {
            txtEE.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("########-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(txNome, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 403, Short.MAX_VALUE)
                                .addComponent(jLabel3))
                            .addComponent(jLabel1))
                        .addGap(11, 11, 11))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel4)
                                    .addComponent(txEndereco, javax.swing.GroupLayout.DEFAULT_SIZE, 403, Short.MAX_VALUE)
                                    .addComponent(txContato, javax.swing.GroupLayout.DEFAULT_SIZE, 403, Short.MAX_VALUE))
                                .addGap(1, 1, 1))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txCidade, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 288, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txCep, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 110, Short.MAX_VALUE))))
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txBairro, javax.swing.GroupLayout.PREFERRED_SIZE, 230, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel11)
                            .addComponent(cmEstado, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(txTelefone, javax.swing.GroupLayout.DEFAULT_SIZE, 110, Short.MAX_VALUE)
                            .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.LEADING))
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(txEmail, javax.swing.GroupLayout.DEFAULT_SIZE, 288, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txCelular, javax.swing.GroupLayout.DEFAULT_SIZE, 110, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel9)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(294, 294, 294)
                                .addComponent(jLabel10)))
                        .addContainerGap(83, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txCPNJ, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel12))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(txtEE, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(192, 192, 192))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap(12, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txContato, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txEndereco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txCidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txCep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8)
                    .addComponent(jLabel11))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txBairro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txTelefone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cmEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jLabel10))
                .addGap(4, 4, 4)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txCelular, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txCPNJ, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtEE, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        btCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ima/cadastro/Cancel.png"))); // NOI18N
        btCancelar.setText("Cancelar");
        btCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCancelarActionPerformed(evt);
            }
        });

        btSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ima/cadastro/Save.png"))); // NOI18N
        btSalvar.setText("Salvar");
        btSalvar.setMaximumSize(new java.awt.Dimension(95, 25));
        btSalvar.setMinimumSize(new java.awt.Dimension(95, 25));
        btSalvar.setPreferredSize(new java.awt.Dimension(95, 25));
        btSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSalvarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(btSalvar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btCancelar)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btCancelar)
                    .addComponent(btSalvar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txEnderecoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txEnderecoActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_txEnderecoActionPerformed

    private void btCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCancelarActionPerformed
}//GEN-LAST:event_btCancelarActionPerformed

    private void btSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSalvarActionPerformed
        try {

            if (!"".equals(txNome.getText())) {
                if (!"".equals(txContato.getText())) {
                    if (!"".equals(txEndereco.getText())) {
                        if (!"".equals(txCidade.getText())) {
                            if (!"".equals(txBairro.getText())) {
                                if (!"".equals(txTelefone.getText())) {

                                    if (edicao == false) {

                                        Fornecedor fornecedor = new Fornecedor();

                                        fornecedor.setNome(txNome.getText());
                                        fornecedor.setContato(txContato.getText());
                                        fornecedor.setEndereco(txEndereco.getText());
                                        fornecedor.setCidade(txCidade.getText());

                                        String cep = txCep.getText().replace(".", "").replace("-", "").trim();

                                        if (!"".equals(cep)) {
                                            fornecedor.setCep(Long.parseLong(cep));
                                        }

                                        fornecedor.setBairro(txBairro.getText());
                                        fornecedor.setEstado(cmEstado.getSelectedItem().toString());

                                        String telefone = txTelefone.getText().replace("(", "").replace(")", "").replace("-", "").trim();

                                        if (!"".equals(telefone)) {
                                            fornecedor.setTelefone(Long.parseLong(telefone));
                                        }

                                        fornecedor.setEmail(txEmail.getText());

                                        String celular = txCelular.getText().replace("(", "").replace(")", "").replace("-", "").trim();

                                        if (!"".equals(celular)) {
                                            fornecedor.setCelular(Long.parseLong(celular));
                                        }

                                        String cnpj = txCPNJ.getText().replace(".", "").replace(".", "").replace("-", "").replace("/", "").trim();

                                        if (!"".equals(cnpj)) {
                                            fornecedor.setCnp(Long.parseLong(cnpj));
                                        }

                                        String ee = txtEE.getText().replace("-", "").trim();

                                        if (!"".equals(ee)) {
                                            fornecedor.setEscricaoestadual(Long.parseLong(ee));
                                        }

                                        daoFornecedor.inserirFornecedor(fornecedor);
                                        
                                         boolean msg = true;

                                        if (msg == true) {
                                            this.hide();
                                            dispose();
                                        } else if (msg == false) {
                                        }
                                        
                                    } else if (edicao == true) {
                                        
                                        fornecedor.setNome(txNome.getText());
                                        fornecedor.setContato(txContato.getText());
                                        fornecedor.setEndereco(txEndereco.getText());
                                        fornecedor.setCidade(txCidade.getText());

                                        String cep = txCep.getText().replace(".", "").replace("-", "").trim();

                                        if (!"".equals(cep)) {
                                            fornecedor.setCep(Long.parseLong(cep));
                                        }

                                        fornecedor.setBairro(txBairro.getText());
                                        fornecedor.setEstado(cmEstado.getSelectedItem().toString());

                                        String telefone = txTelefone.getText().replace("(", "").replace(")", "").replace("-", "").trim();

                                        if (!"".equals(telefone)) {
                                            fornecedor.setTelefone(Long.parseLong(telefone));
                                        }

                                        fornecedor.setEmail(txEmail.getText());

                                        String celular = txCelular.getText().replace("(", "").replace(")", "").replace("-", "").trim();

                                        if (!"".equals(celular)) {
                                            fornecedor.setCelular(Long.parseLong(celular));
                                        }

                                        String cnpj = txCPNJ.getText().replace(".", "").replace(".", "").replace("-", "").replace("/", "").trim();

                                        if (!"".equals(cnpj)) {
                                            fornecedor.setCnp(Long.parseLong(cnpj));
                                        }

                                        String ee = txtEE.getText().replace("-", "").trim();

                                        if (!"".equals(ee)) {
                                            fornecedor.setEscricaoestadual(Long.parseLong(ee));
                                        }
                                        
                                        daoFornecedor.atualizarFornecedor(fornecedor);
                                        
                                        hide();
                                    }

                                } else {
                                    JOptionPane.showMessageDialog(null, "Digite o telefone do fornecedor");
                                    txTelefone.requestFocusInWindow();
                                }
                            } else {
                                JOptionPane.showMessageDialog(null, "Digite o bairro do fornecedor");
                                txBairro.requestFocusInWindow();
                            }
                        } else {
                            JOptionPane.showMessageDialog(null, "Digite a cidade do fornecedor");
                            txCidade.requestFocusInWindow();
                        }
                    } else {
                        JOptionPane.showMessageDialog(null, "Digite o endereço do fornecedor");
                        txEndereco.requestFocusInWindow();
                    }
                } else {
                    JOptionPane.showMessageDialog(null, "Digite o contato do fornecedor");
                    txContato.requestFocusInWindow();
                }
            } else {
                JOptionPane.showMessageDialog(null, "Digite o nome do fornecedor");
                txNome.requestFocusInWindow();
            }


        } catch (Exception e) {
        }

}//GEN-LAST:event_btSalvarActionPerformed

      public void carregarEdicao(Fornecedor fornecedor) {
        try {

            this.setTitle("Editar Fornecedor");

            edicao = true;
            this.fornecedor = fornecedor;

            idFornecedor =  fornecedor.getIdFornecedor();

            txNome.setText(fornecedor.getNome());
            txContato.setText(fornecedor.getContato());
            txEndereco.setText(fornecedor.getEndereco());
            txCidade.setText(fornecedor.getCidade());
            txCep.setText(String.valueOf(fornecedor.getCep()));
            txBairro.setText(fornecedor.getBairro());
            cmEstado.getSelectedItem();
            txTelefone.setText(String.valueOf(fornecedor.getTelefone()));
            txEmail.setText(String.valueOf(fornecedor.getEmail()));
            txCelular.setText(String.valueOf(fornecedor.getCelular()));
            txCPNJ.setText(String.valueOf(fornecedor.getCnp()));
            txtEE.setText(String.valueOf(fornecedor.getEscricaoestadual()));
            
        } catch (Exception e) {
            exceptions.Exceptions(e.getCause().toString(), "CadCliente-carregarEdicao");
        }
    }
      
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                DialogCadFornecedor dialog = new DialogCadFornecedor(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btCancelar;
    private javax.swing.JButton btSalvar;
    private javax.swing.JComboBox cmEstado;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField txBairro;
    private javax.swing.JFormattedTextField txCPNJ;
    private javax.swing.JFormattedTextField txCelular;
    private javax.swing.JFormattedTextField txCep;
    private javax.swing.JTextField txCidade;
    private javax.swing.JTextField txContato;
    private javax.swing.JTextField txEmail;
    private javax.swing.JTextField txEndereco;
    private javax.swing.JTextField txNome;
    private javax.swing.JFormattedTextField txTelefone;
    private javax.swing.JFormattedTextField txtEE;
    // End of variables declaration//GEN-END:variables

  
}
